//
//  ViewController.m
//  LESnowEffect
//
//  Created by 陈记权 on 8/4/16.
//  Copyright © 2016 LeEco. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    CAEmitterLayer *snowEmitter = [CAEmitterLayer layer];
    snowEmitter.backgroundColor = [UIColor orangeColor].CGColor;
    snowEmitter.emitterPosition = CGPointMake(CGRectGetWidth([UIScreen mainScreen].bounds) / 2.0f, -30);
    snowEmitter.emitterSize = CGSizeMake(CGRectGetWidth([UIScreen mainScreen].bounds) / 2, 0.0f);
    snowEmitter.emitterShape = kCAEmitterLayerLine;
    snowEmitter.emitterMode = kCAEmitterLayerVolume;
    
    CAEmitterCell *snowFlake = [CAEmitterCell emitterCell];
    snowFlake.birthRate = 1.0f; // 发射频率
    snowFlake.lifetime = 60.0f;
    snowFlake.velocity = -15.0f;
    snowFlake.velocityRange = 10.0f;
    snowFlake.yAcceleration = 2.0f;
    snowFlake.emissionRange = M_PI_2;
    snowFlake.spinRange = M_PI_4;
    snowFlake.contents = (id)[UIImage imageNamed:@"snow"].CGImage;
    snowFlake.color = [[UIColor colorWithRed:0.600 green:0.658 blue:0.743 alpha:1.000] CGColor];
    
    snowEmitter.shadowOffset = CGSizeMake(0.0f, 1.0f);
    snowEmitter.shadowRadius = 0.0f;
    snowEmitter.shadowOpacity = 1.0f;
    snowEmitter.shadowColor = [UIColor whiteColor].CGColor;
    snowEmitter.emitterCells = @[snowFlake];
    
    [self.view.layer addSublayer:snowEmitter];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
